package one.stand.controller;

import io.swagger.annotations.*;
import one.stand.aop.ApiController;
import one.stand.model.ResultModel;
import one.stand.request.CompanyCouponRequest;
import one.stand.request.CouponStateRequest;
import one.stand.request.CoupponRecordsRequest;
import one.stand.response.CompanyCouponResponse;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author: QIK
 * @CreateDate: 2019/6/24 15:42
 */
@RestController
@RequestMapping("crmPc/company/coupon")
@Api(description = "企业优惠券管理",tags="企业优惠券管理")
public class CompanyCouponController extends BaseController {

    /**
     * 创建优惠券
     * @param request
     * @return
     */
    @ApiOperation(value = "创建优惠券")
    @ApiController(isLogin = true,isBoss = true,paramClass = CompanyCouponRequest.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "name", value = "优惠券名称", required = true, paramType = "String"),
            @ApiImplicitParam(name = "goodstypeId", value = "使用范围", required = true, paramType = "String"),
            @ApiImplicitParam(name = "couponType", value = "优惠类型1满减，2折扣", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "couponFaceValue", value = "优惠券面值", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "couponDiscount", value = "优惠券折扣", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "minAmount", value = "最低消费金额", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "couponType", value = "优惠类型1满减，2折扣", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "effectiveStartTime", value = "有效开始时间", required = true, paramType = "Date"),
            @ApiImplicitParam(name = "effectiveEndTime", value = "有效截止时间", required = true, paramType = "Date"),
            @ApiImplicitParam(name = "grantStartTime", value = "发放开始时间", required = true, paramType = "Date"),
            @ApiImplicitParam(name = "grantEndTime", value = "发放截止时间", required = true, paramType = "Date"),
            @ApiImplicitParam(name = "couponNum", value = "优惠卷发放数量", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "receiveNum", value = "领取数量", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "maxUser", value = "同一用户最多发放", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "pubState", value = "发布状态 默认1禁用 2启用", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "grantMode", value = "发放类型，1：自动发放，2手动领取，3红包发放", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "note", value = "优惠券备注", required = true, paramType = "Integer")
    })
    @PostMapping("add")
    public  ResultModel<Boolean> add(@RequestAttribute CompanyCouponRequest request){
       return crmFegin.add(request);
    }


    @PostMapping("updState")
    @ApiController(isLogin = true,isBoss = true,paramClass = CouponStateRequest.class)
    public  ResultModel<Boolean> updState(@RequestAttribute CouponStateRequest request){
        return crmFegin.updState(request);
    }


    /**
     * 修改优惠券
     * @param request
     * @return
     */
    @ApiOperation(value = "修改优惠券")
    @ApiController(isLogin = true,isBoss = true,paramClass = CompanyCouponRequest.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "couponId", value = "优惠券Id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "name", value = "优惠券名称", required = true, paramType = "String"),
            @ApiImplicitParam(name = "goodstypeId", value = "使用范围", required = true, paramType = "String"),
            @ApiImplicitParam(name = "couponType", value = "优惠类型1满减，2折扣", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "couponFaceValue", value = "优惠券面值", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "couponDiscount", value = "优惠券折扣", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "minAmount", value = "最低消费金额", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "couponType", value = "优惠类型1满减，2折扣", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "effectiveStartTime", value = "有效开始时间", required = true, paramType = "Date"),
            @ApiImplicitParam(name = "effectiveEndTime", value = "有效截止时间", required = true, paramType = "Date"),
            @ApiImplicitParam(name = "grantStartTime", value = "发放开始时间", required = true, paramType = "Date"),
            @ApiImplicitParam(name = "grantEndTime", value = "发放截止时间", required = true, paramType = "Date"),
            @ApiImplicitParam(name = "couponNum", value = "优惠卷发放数量", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "receiveNum", value = "领取数量", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "maxUser", value = "同一用户最多发放多少", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "pubState", value = "发布状态 默认1禁用 2启用", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "grantMode", value = "发放类型，1：自动发放，2手动领取，3红包发放", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "note", value = "优惠券备注", required = true, paramType = "Integer")
    })
    @PostMapping("upd")
    public ResultModel<Boolean> upd(@RequestAttribute CompanyCouponRequest request){
        return crmFegin.upd(request);
    }

    @PostMapping("findCompanyCouponById")
    @ApiOperation(value = "查询单个优惠券")
    @ApiImplicitParam(name = "couponId", value = "优惠券ID", required = true, paramType = "Integer")
    @ApiController(isLogin = true, company = true, card = true, paramClass = CompanyCouponRequest.class)
    public ResultModel<CompanyCouponResponse> findCompanyCouponById(@RequestAttribute CompanyCouponRequest request){
        return crmFegin.findCompanyCouponById(request);
    }


    /**
     * 删除优惠券
     * @return
     */
    @ApiOperation(value = "删除优惠券")
    @ApiController(isLogin = true,isBoss = true,paramClass = CouponStateRequest.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "couponId", value = "Id", required = true, paramType = "Integer")
    })
    @PostMapping("del")
    public  ResultModel<Boolean> del( @RequestAttribute CouponStateRequest request){
        return crmFegin.del(request);
    }
    /**
     * 删除优惠券
     * @param request
     * @return
     */
    @ApiOperation(value = "优惠券列表")
    @ApiController(isLogin = true,isBoss = true,paramClass = CompanyCouponRequest.class)
    @PostMapping("crmPcPageList")
    public  ResultModel crmPcPageList(@RequestAttribute CompanyCouponRequest request){
        return crmFegin.crmPcPageList(request);
    }

    /**
     * 领取记录查询
     * @param request
     * @return
     */
    @ApiOperation(value = "领取记录查询")
    @ApiController(isLogin = true,isBoss = true,paramClass = CoupponRecordsRequest.class)
    @PostMapping("coupponRecords")
    public  ResultModel coupponRecords(@RequestAttribute CoupponRecordsRequest request){
        return crmFegin.coupponRecords(request);
    }
}
